<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>test.html</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <script src="WebSocket.js"></script>
	<script type="text/javascript">
	var socket = null;
	
	function initApp(){
		
	}
	
	function openWebSocket(){
		socket = new WebSocket("flash1");
		socket.addEvent("onIOError","onIOError");
		socket.addEvent("onSocketData","onSocketData");
		socket.addEvent("onClose","onClose");
		socket.addEvent("onConnect","onConnect");
		socket.open("127.0.0.1",8888);
	}
	
	function closeWebSocket(){
		socket.close();
	}
	
	function isOpen(){
		alert(socket.isOpen());
	}
	
	function onIOError(){
		alert("连接错误");
	}
	function onSocketData(msg){
		document.getElementById("debug").value += "\n"+msg;
	}
	function onClose(){
		alert("连接关闭");
	}
	function onConnect(){
		alert("连接成功");
	}
	
	function sendData(){
		var msg = document.getElementById("text").value;
		socket.sendData(msg);
		document.getElementById("text").value="";
	}
	</script>
  </head>
  
  <body onload="initApp();">
    <object id="flash1" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="0" height="0">
		<param name="movie" value="WebSocket.swf" />
		<param name="quality" value="high" />
		<param name="wmode" value="transparent" />
		<embed src="WebSocket.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="0" height="0"></embed>
	</object>
	
	<textarea id="debug" rows="8" cols="40"></textarea><br>
	<textarea id="text" rows="8" cols="40">userLogin?name=刘伟</textarea><br>
	<button onclick="sendData();">发送信息</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	<button onclick="isOpen();">是否打开</button>
	<button onclick="openWebSocket();">连接服务</button>
	<button onclick="closeWebSocket();">关闭连接</button>
	
  </body>
</html>
